#include "StdAfx.h"
#include "DIActor.h"
#include "../Engine/DAnimation.h"
#include "../Game/DGame.h"

////////////// Graphics Params ///////////

DGraphicsParams::DGraphicsParams()
: m_redChannel(255)
, m_greenChannel(255)
, m_blueChannel(255)
, m_alphaChannel(255)
, m_bFlippedX(false)
, m_bFlippedY(false)
{

}

void DGraphicsParams::setRedChannel(int red)
{
    m_redChannel = red;
}

void DGraphicsParams::setGreenChannel(int green)
{
    m_greenChannel = green;
}

void DGraphicsParams::setBlueChannel(int blue)
{
    m_blueChannel = blue;
}

void DGraphicsParams::setAlphaChannel(int alpha)
{
    m_alphaChannel = alpha;
}

void DGraphicsParams::setColorChannels(int red, int green, int blue, int alpha)
{
    m_redChannel = red;
    m_greenChannel = green;
    m_blueChannel = blue;
    m_alphaChannel = alpha;
}

void DGraphicsParams::setFlippedX(bool flipped)
{
    m_bFlippedX = flipped;
}

void DGraphicsParams::setFlippedY(bool flipped)
{
    m_bFlippedY = flipped;
}

void DGraphicsParams::setFlipped(bool x, bool y)
{
    m_bFlippedX = x;
    m_bFlippedY = y;
}

int DGraphicsParams::redChannel() const
{
    return m_redChannel;
}

int DGraphicsParams::greenChannel() const
{
    return m_greenChannel;
}

int DGraphicsParams::blueChannel() const
{
    return m_blueChannel;
}

int DGraphicsParams::alphaChannel() const
{
    return m_alphaChannel;
}

bool DGraphicsParams::isFlippedX() const
{
    return m_bFlippedX;
}

bool DGraphicsParams::isFlippedY() const
{
    return m_bFlippedY;
}

/////////////////////////////////////////////////

DIActor::DIActor(boost::shared_ptr<DGame> game)
: m_game(game)
, m_scale(1.0f, 1.0f)
{
}

DIActor::~DIActor(void)
{
}

boost::shared_ptr<DAnimation> DIActor::currentAnimation()
{
	return m_currentAnim.lock();
}

void DIActor::addAnimation(const std::string& name, boost::shared_ptr<DAnimation> anim)
{
	m_anims[name] = anim;
}

void DIActor::setCurrentAnimation(const std::string& name)
{
	m_currentAnim = m_anims[name];
}

const DGraphicsParams& DIActor::graphicsParams() const
{
    return m_graphicsParams;
}

DGraphicsParams& DIActor::graphicsParams()
{
    return m_graphicsParams;
}

const vec2& DIActor::pos()
{
    return m_pos;
}

void DIActor::setPos(const vec2& pos)
{
    m_pos = pos;
}

const vec2& DIActor::scale()
{
    return m_scale;
}

void DIActor::setScale(const vec2& scale)
{
    m_scale = scale;
}

boost::shared_ptr<DGame> DIActor::game() const
{
    return m_game.lock();
}

void DIActor::updateMoving(float dt)
{
	m_vel += m_acc*dt;
	m_pos += m_vel*dt;
}

void DIActor::initWeapons()
{
    // NOTE: weapon could be instantiated in constructor but shared_from_this() couldn't be called from ctor
    // so we have to make 2 step init
    assert(false);
}